package controller

import (
	"github.com/gin-gonic/gin"
	"lab.com/biz"
	"lab.com/request"
)

type cNews struct {
	APIBase
}

// News .
var News = cNews{}

// List return news list (all user)
func (news *cNews) List(c *gin.Context) {
	inputParams := request.NewsListReq{}
	if err := inputParams.CheckInputParams(c); err != nil {
		news.Resp(c, nil, err)
		return
	}

	res, err := biz.News.List(c, inputParams)
	news.Resp(c, res, err)
}

// Detail return news detail (all user)
func (news *cNews) Detail(c *gin.Context) {
	inputParams := request.NewsDetailReq{}
	if err := inputParams.CheckInputParams(c); err != nil {
		news.Resp(c, nil, err)
		return
	}

	res, err := biz.News.Detail(c, inputParams)
	news.Resp(c, res, err)
}

// Add return news add (admin)
func (news *cNews) Add(c *gin.Context) {
	inputParams := request.NewsAddReq{}
	if err := inputParams.CheckInputParams(c); err != nil {
		news.Resp(c, nil, err)
		return
	}

	err := biz.News.Add(c, inputParams)
	news.Resp(c, nil, err)
}

// Delete return news delete (admin)
func (news *cNews) Delete(c *gin.Context) {
	inputParams := request.NewsDeleteReq{}
	if err := inputParams.CheckInputParams(c); err != nil {
		news.Resp(c, nil, err)
		return
	}

	err := biz.News.Delete(c, inputParams)
	news.Resp(c, nil, err)
}

// Edit return news edit (admin)
func (news *cNews) Edit(c *gin.Context) {
	inputParams := request.NewsEditReq{}
	if err := inputParams.CheckInputParams(c); err != nil {
		news.Resp(c, nil, err)
		return
	}

	err := biz.News.Edit(c, inputParams)
	news.Resp(c, nil, err)
}

// Show return news show (admin)
func (news *cNews) Show(c *gin.Context) {
	inputParams := request.NewsShowReq{}
	if err := inputParams.CheckInputParams(c); err != nil {
		news.Resp(c, nil, err)
		return
	}

	err := biz.News.Show(c, inputParams)
	news.Resp(c, nil, err)
}

// Home return news ome (admin)
func (news *cNews) Home(c *gin.Context) {
	inputParams := request.NewsHomeReq{}
	if err := inputParams.CheckInputParams(c); err != nil {
		news.Resp(c, nil, err)
		return
	}

	err := biz.News.Home(c, inputParams)
	news.Resp(c, nil, err)
}

// ListInManage return news list in manage (admin)
func (news *cNews) ListInManage(c *gin.Context) {
	inputParams := request.NewsListInManageReq{}
	if err := inputParams.CheckInputParams(c); err != nil {
		news.Resp(c, nil, err)
		return
	}

	res, err := biz.News.ListInManage(c, inputParams)
	news.Resp(c, res, err)
}
